-- open_grid_recover
-- created by zhuangsl
-- 每开启一个格子，属性回复N

return {
    apply = function(prop, baseValue)
        -- 回复的值
        return prop[3];
    end,

    -- 开格子时触发
    trigger = function(who, prop, arg)
        local attrib = prop[2];
        local v = prop[3];
        local now;
        local max;
        local pos = arg;

        -- 如果是hp和mp
        if attrib == "hp" then
            now = who:getHp()
            max = who:getMaxHp();
        elseif attrib == "mp" then
            now = who:getMp()
            max = who:getMaxMp();
        end

        local bonus = {2, attrib, v};

        if max and max > 0 and now >= max then
            return false;
        else
            BonusM.doBonus(bonus, "open_grid_recover");
        end

        -- 事件
        if attrib == "money" then
            EventMgr.fire(event.OPEN_GRID_MONEY, {["bonus"] = bonus,
                ["pos"] = pos, ["newBonus"] = nil, });
        end

        return v;
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;

        local attrib = prop[2];
        if prop[2] == "search_point" then
            desc = row.append_desc;
        end

        local num = prop[3];
        local attrib = FieldsM.getFieldName(prop[2]);
        desc = string.gsub(desc, "{0}", attrib);

        desc = string.gsub(desc, "{1}", num);

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end
};